package com.luyuan.crm.user.support;

import java.util.List;

import org.hibernate.criterion.Order;

import com.luyuan.crm.user.PartyGroup;
import com.luyuan.crm.user.service.PartyGroupService;
import com.ruijie.foundation.dao.extend.support.HibernateEntityExtendDao;
import com.ruijie.foundation.query.Page;
import com.ruijie.foundation.query.criteria.CriteriaQueryTemplate;
import com.ruijie.foundation.query.criteria.CriteriaTemplate;

public class PartyGroupServiceImpl extends HibernateEntityExtendDao<PartyGroup> implements PartyGroupService {

    @Override
    public PartyGroup getById(String id) {
        return safeGet(id);
    }

    @Override
    public void addPartyGroup(PartyGroup partyGroup) {
        save(partyGroup);
    }

    @Override
    public void removePartyGroup(PartyGroup partyGroup) {
        update("update PartyGroup set parentGroup = null where parentGroup = ?", partyGroup);
        update("update Party set partyGroup = null where partyGroup = ?", partyGroup);
        remove(partyGroup);
    }

    @Override
    public void updatePartyGroup(PartyGroup partyGroup) {
        evit(partyGroup);
        getHibernateTemplate().merge(partyGroup);
    }

    @Override
    public Page pagedQuery(CriteriaTemplate criteria, int pageNo, int pageSize, List<Order> orders) {
        CriteriaQueryTemplate qt = new CriteriaQueryTemplate(getSessionFactory());
        return qt.pagedQuery(criteria, pageNo, pageSize, orders);
    }

}
